//
//  StoreEditCell.swift
//  Share
//
//  Created by admin on 2020/10/9.
//  Copyright © 2020 MBA. All rights reserved.
//

import SwiftUI

typealias StoreEditCellDeleteClosure = () -> Void
typealias StoreEditCellEditClosure = () -> Void

struct StoreEditCell: View {
    
    @Binding var store:Store
    @State var deleteAction: StoreEditCellDeleteClosure?
    @State var editAction: StoreEditCellEditClosure?
    
    func editStore() {
        self.editAction?()
    }
    func deleteStore()  {
        self.deleteAction?()
    }
    
    
    
    var body: some View {
        
        HStack {
            
            
            VStack(alignment: .leading) {
                Text("持有\(store.num)")
                    .font(.system(size: 18))
                    .foregroundColor( Color("lable1"))
                
                HStack {
                    Text("价格\(store.price, specifier: "%0.3f")")
                    Text("时间\(store.day ?? "--")")
                }
                .font(.system(size: 14))
                .foregroundColor( Color("lable2"))
                .padding(.top)
            }
            
            
            
            Spacer()
            HStack {
                Button(action: editStore) {
                    Image(systemName: "square.and.pencil")
                        .frame(width: 32, height: 32, alignment: .center)
                    
                }
                Button(action: deleteStore) { Image(systemName: "trash")
                    .frame(width: 32, height: 32, alignment: .center) }
                
                
            }
        }
        .padding(.all)
        .font(.system(size: 14))
        .background(Color("background3"))
        .cornerRadius(8)
        .shadow(color: Color("shadow"), radius: 4, x: -1, y: 4)
        
    }
}

struct StoreEditCell_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            StoreEditCell(store:.constant(Store._stores[0]) )
                .previewLayout(.sizeThatFits)
        }
    }
}
